#include <iostream>
using namespace std;

class TextBlock
{
  public:
    TextBlock(string s)
        : text(s)
    {
    }

    TextBlock(const TextBlock &t)
        : text(t.text)
    {
    }

    const char &operator[](size_t position) const
    {
        return text[position];
    }

    char &operator[](size_t position)
    {
        return const_cast<char &>(                // 将op[]返回值的const移除
            static_cast<const TextBlock &>(*this) // 为*this加上const
                [position]                        // 调用const op[]
        );
    }

  private:
    string text;
};

int main()
{
    const TextBlock ct("Hello");
    cout << ct[0] << endl;
    TextBlock t("Hello");
    cout << t[0] << endl;
}
